//
//  BlockView.m
//  CoreGraphicsTest
//
//  Created by aewatson on 11/19/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BlockView.h"


@implementation BlockView

@synthesize blockModel;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithBlockModel:(BlockModel*) newBlockModel {
    self = [super init];
    [self setBlockModel:newBlockModel];
    // set size & location
    CGRect rect = CGRectMake([blockModel getLeft], [blockModel getTop], [blockModel getWidth], [blockModel getHeight]);
    [self setFrame:rect];
    // set color
    UIColor *color = [[[UIColor alloc] init] autorelease];
    switch ([blockModel getColor]) {
        case RED:
            color = [UIColor redColor];
            break;
        case GREEN:
            color = [UIColor greenColor];
            break;
        case BLUE:
            color = [UIColor blueColor];
            break;
        default:
            break;
    }
    [self setBackgroundColor:color];
    return self;
}

- (void)updateFromModel {
    [self setCenter:CGPointMake([blockModel centerX], [blockModel centerY])];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc
{
    [super dealloc];
}

@end
